package com.ztc.ZtcRefundRecord.web;

import com.aqgj.User.bean.User;
import com.aqgj.util.JsonWrapper;
import com.ztc.ZtcOrder.bean.ZtcOrder;
import com.ztc.ZtcOrder.service.ZtcOrderManager;
import com.ztc.ZtcRefundRecord.bean.ZtcRefundRecord;
import com.ztc.ZtcRefundRecord.service.ZtcRefundRecordManager;
import com.ztc.ZtcTransport.bean.ZtcTransport;
import com.ztc.ZtcTransport.service.ZtcTransportManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;


@Controller
@RequestMapping("RefundRecord")
public class ZtcRefundRecordAction {

    @Autowired
    private ZtcRefundRecordManager ztcRefundRecordManager;
    @Autowired
    private ZtcTransportManager ztcTransportManager;
    @Autowired
    private ZtcOrderManager ztcOrderManager;

    /**
     * 获取当前公司退款列表.
     * @param pageNo    页码
     * @param pageSize  条数
     * @param session
     * @return
     */
    @RequestMapping("getRecordSumAndList")
    @ResponseBody
    public HashMap<String,Object>  getRecordSumAndList(int pageNo, int pageSize, HttpSession session) {
        User user=(User)session.getAttribute("userInfo");
        ZtcTransport ztcTransport=ztcTransportManager.get(user.getTransportId());
        if(ztcTransport==null){
            return JsonWrapper.failureWrapperMsg("信息获取失败，请稍后重试！");
        }
        List<Object> list = ztcRefundRecordManager.getRecordList(pageNo,pageSize,ztcTransport.getType(),ztcTransport.getId());
        return JsonWrapper.successPagerWrapper(list,ztcRefundRecordManager.getSqlSumQuery(ztcTransport.getType(),ztcTransport.getId()));
    }

    /**
     * 获取退款记录详情.
     * @param rid  退款记录id
     * @return
     */
    @RequestMapping("getRecordInfo")
    @ResponseBody
    public HashMap<String,Object>  getRecordInfo(String rid) {
        ZtcRefundRecord ztcRefundRecord=ztcRefundRecordManager.get(rid);
        if(ztcRefundRecord==null){
            return JsonWrapper.failureWrapperMsg("信息获取失败，请稍后重试！");
        }
       ZtcOrder ztcOrder= ztcOrderManager.get(ztcRefundRecord.getFkOrderId());
        if(ztcOrder==null){
            return JsonWrapper.failureWrapperMsg("订单数据异常，请稍后重试！");
        }
        return ztcRefundRecordManager.getRecordInfo(rid,ztcOrder.getOrderType());
    }


}